/*
 * @Author: ZhanXie
 * @Date: 2020-03-10 18:11:14
 * @LastEditors: ZhanXie
 * @LastEditTime: 2020-03-10 18:12:20
 * @Description: cookie 操作
 * @FilePath: /projectStudy/ts-axios/src/helpers/cookie.ts
 */

const cookie = {
  /**
   * `cookie` 的读取逻辑很简单，利用了正则表达式可以解析到 `name` 对应的值。
   * @param name
   */
  read(name: string): string | null {
    const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'))
    return match ? decodeURIComponent(match[3]) : null
  }
}

export default cookie
